<?php
/**
 * Url帮助类
 * User: Woozee
 * Date: 2020/12/8
 * Time: 22:20
 */

namespace App\Helpers;

class Url
{
    public static function getQiniuUrl(string $key): string
    {
        $domain = trim(config('qiniu.domain'), '/');

        return "{$domain}/" . trim($key, '/');
    }

    /**
     * 通过链接获取头信息
     *
     * @param string $path
     * @return array
     */
    public static function getHeaders(string $path): array
    {
        $result = [];
        $headers = get_headers($path, 1);
        if (!empty($headers['Content-Length'])) {
            foreach ($headers['Content-Length'] as $length) {
                if ($length) {
                    $result['Content-Length'] = $length;
                }
            }
        }
        $result['Content-Type'] = $headers['Content-Type'];
        return $result;
    }
}
